package test.baojia.act.operation;

import com.alibaba.fastjson.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Bootstrap auto complete控件操作。
 */
public class BsAutoCompleteOperation extends InputOperation {

    private final static String CSS_SELECTOR_UI = "#%s +ul.dropdown-menu";

    public void run(JSONObject context, WebDriver driver, Properties resource, JSONObject parentContext) throws  Exception {
        super.run(context , driver , resource, parentContext);

        final String selector = String.format(CSS_SELECTOR_UI , context.get(OPERATION.byExp.toString()));
        this.newWebDriverWait(null).until(
                ExpectedConditions.visibilityOfElementLocated(By.cssSelector(selector))
        );

        Map jsContext = new HashMap<String , Object>();
        jsContext.put("ulCssSelector" , selector);
        this.runDefaultJsScript(this , jsContext);

        //补充测试是否有AUTO COMPLETE效果的代码。
    }

}
